package online.chazi.bootplus.multiple.redis;

import org.springframework.beans.InvalidPropertyException;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 叉子同学 on 2020-03-04 10:41
 */
public class MultipleRedisManager<K, V> {

    private ConcurrentHashMap<String, RedisTemplate<K, V>> multiple = new ConcurrentHashMap<>();

    public void put(String name, RedisTemplate<K, V> config) {
        if (name == null || multiple.containsKey(name))
            throw new InvalidPropertyException(MultipleRedisProperties.class, "name", "name属性值必须唯一且非空。已经存在name=" + name);
        multiple.put(name, config);
    }

    public RedisTemplate<K, V> getRedisTemplate(String name) {
        RedisTemplate<K, V> template = multiple.get(name);
        template.afterPropertiesSet();
        return template;
    }

}
